/**
  \file TestCase_DawgArr.cpp
  \author Francis Girard
  \date 17 october 2013
*/


/*
 *  Copyright (C) 2013, Francis Girard
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/config/SourcePrefix.h>

#include "dawg_arr_void_ptr.h"


class TestCase_DawgArr : public CPPUNIT_NS::TestFixture
{
  CPPUNIT_TEST_SUITE( TestCase_DawgArr );
  CPPUNIT_TEST( test_create );
  CPPUNIT_TEST( test_allocate );
  CPPUNIT_TEST( test_push_back );
  CPPUNIT_TEST( test_front_and_last );
  CPPUNIT_TEST( test_append_empty_empty );
  CPPUNIT_TEST( test_append_snd_empty );
  CPPUNIT_TEST( test_append_fst_empty );
  CPPUNIT_TEST( test_append_others );
  CPPUNIT_TEST( test_begin_end_one );
  CPPUNIT_TEST( test_begin_end_two );
  CPPUNIT_TEST( test_begin_end_three );
  CPPUNIT_TEST( test_before_begin_one );
  CPPUNIT_TEST( test_before_begin_two );
  CPPUNIT_TEST( test_is_empty_empty );
  CPPUNIT_TEST( test_is_empty_others );
  CPPUNIT_TEST( test_substitute_empty );
  CPPUNIT_TEST( test_substitute_one );
  CPPUNIT_TEST( test_substitute_two );
  CPPUNIT_TEST( test_substitute_multi );
  CPPUNIT_TEST( test_sort_empty );
  CPPUNIT_TEST( test_sort_one );
  CPPUNIT_TEST( test_sort_two );
  CPPUNIT_TEST( test_sort_many );
  CPPUNIT_TEST_SUITE_END();

public:
  void setUp();
  void tearDown();

protected:
  void test_create();
  void test_allocate();
  void test_push_back();
  void test_front_and_last();
  void test_append_empty_empty();
  void test_append_snd_empty();
  void test_append_fst_empty();
  void test_append_others();
  void test_begin_end_one();
  void test_begin_end_two();
  void test_begin_end_three();
  void test_before_begin_one();
  void test_before_begin_two();
  void test_is_empty_empty();
  void test_is_empty_others();
  void test_substitute_empty();
  void test_substitute_one();
  void test_substitute_two();
  void test_substitute_multi();
  void test_sort_empty();
  void test_sort_one();
  void test_sort_two();
  void test_sort_many();
};
CPPUNIT_TEST_SUITE_REGISTRATION( TestCase_DawgArr );


void TestCase_DawgArr::setUp()
{
}

void TestCase_DawgArr::tearDown()
{
}

void TestCase_DawgArr::test_create()
{
  h_dawg_arr_void_ptr hNewArr = dawg_arr_void_ptr_create();
  CPPUNIT_ASSERT( hNewArr != 0 );

  unsigned int nSize = dawg_arr_void_ptr_size(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, nSize );

  unsigned int nCapacity = dawg_arr_void_ptr_capacity(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, nCapacity );

  dawg_arr_void_ptr_destroy(hNewArr);
}

void TestCase_DawgArr::test_allocate()
{
  h_dawg_arr_void_ptr hNewArr = dawg_arr_void_ptr_allocate(7);
  CPPUNIT_ASSERT( hNewArr != 0 );

  unsigned int nSize = dawg_arr_void_ptr_size(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, nSize );

  unsigned int nCapacity = dawg_arr_void_ptr_capacity(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 7, nCapacity );

  dawg_arr_void_ptr_destroy(hNewArr);
}

void TestCase_DawgArr::test_push_back()
{
  unsigned int nLoop = 0;
  for ( ; nLoop < 2; nLoop++ )
  {
      h_dawg_arr_void_ptr hNewArr = 0;
      if (nLoop)
      {
        hNewArr = dawg_arr_void_ptr_create();
      }
      else
      {
        hNewArr = dawg_arr_void_ptr_allocate(3);
        CPPUNIT_ASSERT_EQUAL( (unsigned int) 3, dawg_arr_void_ptr_capacity(hNewArr) );
      }

      CPPUNIT_ASSERT( hNewArr != 0 );
      CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, dawg_arr_void_ptr_size(hNewArr) );

      dawg_arr_void_ptr_push_back(hNewArr, (void*) 661);
      CPPUNIT_ASSERT_EQUAL( (unsigned int) 1, dawg_arr_void_ptr_size(hNewArr) );
      dawg_arr_void_ptr_push_back(hNewArr, (void*) 662);
      CPPUNIT_ASSERT_EQUAL( (unsigned int) 2, dawg_arr_void_ptr_size(hNewArr) );
      dawg_arr_void_ptr_push_back(hNewArr, (void*) 663);
      CPPUNIT_ASSERT_EQUAL( (unsigned int) 3, dawg_arr_void_ptr_size(hNewArr) );

      CPPUNIT_ASSERT( dawg_arr_void_ptr_capacity(hNewArr) >= dawg_arr_void_ptr_size(hNewArr) );
      CPPUNIT_ASSERT_EQUAL( (void*) 661, dawg_arr_void_ptr_get_el(hNewArr, 0) );
      CPPUNIT_ASSERT_EQUAL( (void*) 662, dawg_arr_void_ptr_get_el(hNewArr, 1) );
      CPPUNIT_ASSERT_EQUAL( (void*) 663, dawg_arr_void_ptr_get_el(hNewArr, 2) );

      dawg_arr_void_ptr_push_back(hNewArr, (void*) 664);
      CPPUNIT_ASSERT_EQUAL( (unsigned int) 4, dawg_arr_void_ptr_size(hNewArr) );
      dawg_arr_void_ptr_push_back(hNewArr, (void*) 665);
      CPPUNIT_ASSERT_EQUAL( (unsigned int) 5, dawg_arr_void_ptr_size(hNewArr) );
      dawg_arr_void_ptr_push_back(hNewArr, (void*) 666);
      CPPUNIT_ASSERT_EQUAL( (unsigned int) 6, dawg_arr_void_ptr_size(hNewArr) );
      dawg_arr_void_ptr_push_back(hNewArr, (void*) 667);
      CPPUNIT_ASSERT_EQUAL( (unsigned int) 7, dawg_arr_void_ptr_size(hNewArr) );

      CPPUNIT_ASSERT( dawg_arr_void_ptr_capacity(hNewArr) >= dawg_arr_void_ptr_size(hNewArr) );
      CPPUNIT_ASSERT_EQUAL( (void*) 664, dawg_arr_void_ptr_get_el(hNewArr, 3) );
      CPPUNIT_ASSERT_EQUAL( (void*) 665, dawg_arr_void_ptr_get_el(hNewArr, 4) );
      CPPUNIT_ASSERT_EQUAL( (void*) 666, dawg_arr_void_ptr_get_el(hNewArr, 5) );
      CPPUNIT_ASSERT_EQUAL( (void*) 667, dawg_arr_void_ptr_get_el(hNewArr, 6) );

      dawg_arr_void_ptr_destroy(hNewArr);
  }
}

void TestCase_DawgArr::test_front_and_last()
{
  h_dawg_arr_void_ptr hNewArr = 0;
  hNewArr = dawg_arr_void_ptr_create();
  dawg_arr_void_ptr_push_back(hNewArr, (void*) 666);

  void* pFetched = dawg_arr_void_ptr_front(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (void*) 666, pFetched );
  pFetched = dawg_arr_void_ptr_last(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (void*) 666, pFetched );

  dawg_arr_void_ptr_push_back(hNewArr, (void*) 667);

  pFetched = dawg_arr_void_ptr_front(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) pFetched );
  pFetched = dawg_arr_void_ptr_last(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) pFetched );

  dawg_arr_void_ptr_push_back(hNewArr, (void*) 668);

  pFetched = dawg_arr_void_ptr_front(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) pFetched );
  pFetched = dawg_arr_void_ptr_last(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) pFetched );

  dawg_arr_void_ptr_push_back(hNewArr, (void*) 669);
  dawg_arr_void_ptr_push_back(hNewArr, (void*) 670);
  dawg_arr_void_ptr_push_back(hNewArr, (void*) 671);
  dawg_arr_void_ptr_push_back(hNewArr, (void*) 672);
  dawg_arr_void_ptr_push_back(hNewArr, (void*) 673);
  dawg_arr_void_ptr_push_back(hNewArr, (void*) 674);

  pFetched = dawg_arr_void_ptr_front(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) pFetched );
  pFetched = dawg_arr_void_ptr_last(hNewArr);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 674, (unsigned int) pFetched );

  dawg_arr_void_ptr_destroy(hNewArr);
}


void TestCase_DawgArr::test_append_empty_empty()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  h_dawg_arr_void_ptr hArr2 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_append(hArr1, hArr2);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, dawg_arr_void_ptr_size(hArr1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, dawg_arr_void_ptr_size(hArr2) );

  dawg_arr_void_ptr_destroy(hArr1);
  dawg_arr_void_ptr_destroy(hArr2);
}


void TestCase_DawgArr::test_append_snd_empty()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  h_dawg_arr_void_ptr hArr2 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  dawg_arr_void_ptr_append(hArr1, hArr2);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1, dawg_arr_void_ptr_size(hArr1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, dawg_arr_void_ptr_size(hArr2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );

  dawg_arr_void_ptr_push_back(hArr1, (void*) 667);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 668);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 669);

  dawg_arr_void_ptr_append(hArr1, hArr2);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 4, dawg_arr_void_ptr_size(hArr1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, dawg_arr_void_ptr_size(hArr2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 3) );

  dawg_arr_void_ptr_destroy(hArr1);
  dawg_arr_void_ptr_destroy(hArr2);
}


void TestCase_DawgArr::test_append_fst_empty()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  h_dawg_arr_void_ptr hArr2 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_push_back(hArr2, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr2, (void*) 667);
  dawg_arr_void_ptr_push_back(hArr2, (void*) 668);
  dawg_arr_void_ptr_push_back(hArr2, (void*) 669);

  dawg_arr_void_ptr_append(hArr1, hArr2);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 4, dawg_arr_void_ptr_size(hArr1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 4, dawg_arr_void_ptr_size(hArr2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 3) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 3) );

  dawg_arr_void_ptr_append(hArr1, hArr2);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 8, dawg_arr_void_ptr_size(hArr1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 4, dawg_arr_void_ptr_size(hArr2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 3) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 4) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 5) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 6) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 7) );

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 3) );

  dawg_arr_void_ptr_destroy(hArr1);
  dawg_arr_void_ptr_destroy(hArr2);
}


void TestCase_DawgArr::test_append_others()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  h_dawg_arr_void_ptr hArr2 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_push_back(hArr1, (void*) 1666);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 1667);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 1668);

  dawg_arr_void_ptr_push_back(hArr2, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr2, (void*) 667);
  dawg_arr_void_ptr_push_back(hArr2, (void*) 668);
  dawg_arr_void_ptr_push_back(hArr2, (void*) 669);

  dawg_arr_void_ptr_append(hArr1, hArr2);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 7, dawg_arr_void_ptr_size(hArr1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 4, dawg_arr_void_ptr_size(hArr2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  3) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  4) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  5) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  6) );

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr2, 3) );

  dawg_arr_void_ptr_append(hArr1, hArr1);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 14, dawg_arr_void_ptr_size(hArr1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  3) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  4) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  5) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  6) );

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 7) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 8) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 9) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  10) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  11) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  12) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr1,  13) );

  dawg_arr_void_ptr_destroy(hArr1);
  dawg_arr_void_ptr_destroy(hArr2);
}


void TestCase_DawgArr::test_begin_end_one()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);

  h_dawg_arr_void_ptr_it itCur = dawg_arr_void_ptr_begin(hArr1);
  h_dawg_arr_void_ptr_it itEnd = dawg_arr_void_ptr_end(hArr1);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur < itEnd );
  itCur++;
  CPPUNIT_ASSERT( itCur == itEnd );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_begin_end_two()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 667);

  h_dawg_arr_void_ptr_it itCur = dawg_arr_void_ptr_begin(hArr1);
  h_dawg_arr_void_ptr_it itEnd = dawg_arr_void_ptr_end(hArr1);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur < itEnd );
  itCur++;
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur < itEnd );
  itCur++;
  CPPUNIT_ASSERT( itCur == itEnd );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_begin_end_three()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 667);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 668);

  h_dawg_arr_void_ptr_it itCur = dawg_arr_void_ptr_begin(hArr1);
  h_dawg_arr_void_ptr_it itEnd = dawg_arr_void_ptr_end(hArr1);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur < itEnd );
  itCur++;
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur < itEnd );
  itCur++;
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur < itEnd );
  itCur++;
  CPPUNIT_ASSERT( itCur == itEnd );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_before_begin_one()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);

  h_dawg_arr_void_ptr_it itCur = dawg_arr_void_ptr_begin(hArr1);
  h_dawg_arr_void_ptr_it itBeforeBegin = dawg_arr_void_ptr_before_begin(hArr1);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur > itBeforeBegin );
  itCur--;
  CPPUNIT_ASSERT( itCur == itBeforeBegin );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_before_begin_two()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 667);

  h_dawg_arr_void_ptr_it itCur = dawg_arr_void_ptr_end(hArr1);
  h_dawg_arr_void_ptr_it itBeforeBegin = dawg_arr_void_ptr_before_begin(hArr1);

  CPPUNIT_ASSERT( itCur > itBeforeBegin );
  itCur--;
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur > itBeforeBegin );
  itCur--;
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) *itCur );
  CPPUNIT_ASSERT( itCur > itBeforeBegin );
  itCur--;
  CPPUNIT_ASSERT( itCur == itBeforeBegin );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_is_empty_empty()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_bool_t bEmpty = dawg_arr_void_ptr_is_empty(hArr1);
  CPPUNIT_ASSERT_EQUAL( (unsigned char) dawg_true, (unsigned char) bEmpty );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_is_empty_others()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_bool_t bEmpty = dawg_arr_void_ptr_is_empty(hArr1);
  CPPUNIT_ASSERT_EQUAL( (unsigned char) dawg_true, (unsigned char) bEmpty );

  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  bEmpty = dawg_arr_void_ptr_is_empty(hArr1);
  CPPUNIT_ASSERT_EQUAL( (unsigned char) dawg_false, (unsigned char) bEmpty );

  dawg_arr_void_ptr_push_back(hArr1, (void*) 667);
  bEmpty = dawg_arr_void_ptr_is_empty(hArr1);
  CPPUNIT_ASSERT_EQUAL( (unsigned char) dawg_false, (unsigned char) bEmpty );

  dawg_arr_void_ptr_push_back(hArr1, (void*) 668);
  bEmpty = dawg_arr_void_ptr_is_empty(hArr1);
  CPPUNIT_ASSERT_EQUAL( (unsigned char) dawg_false, (unsigned char) bEmpty );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_substitute_empty()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_bool_t bSubstituted = dawg_arr_void_ptr_substitute(hArr1, (void*) 666, (void*) 1666);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) dawg_false, (unsigned int) bSubstituted );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, dawg_arr_void_ptr_size(hArr1));

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_substitute_one()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);

  dawg_bool_t bSubstituted = dawg_arr_void_ptr_substitute(hArr1, (void*) 999, (void*) 1999);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) dawg_false, (unsigned int) bSubstituted );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666,
                        (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );

  bSubstituted = dawg_arr_void_ptr_substitute(hArr1, (void*) 666, (void*) 1666);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) dawg_true, (unsigned int) bSubstituted );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_substitute_two()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 665);

  dawg_bool_t bSubstituted = dawg_arr_void_ptr_substitute(hArr1, (void*) 999, (void*) 1999);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) dawg_false, (unsigned int) bSubstituted );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 2, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 665, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );

  bSubstituted = dawg_arr_void_ptr_substitute(hArr1, (void*) 666, (void*) 1666);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) dawg_true, (unsigned int) bSubstituted );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 2, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 665, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );

  bSubstituted = dawg_arr_void_ptr_substitute(hArr1, (void*) 665, (void*) 1665);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) dawg_true, (unsigned int) bSubstituted );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 2, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1665, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_substitute_multi()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 665);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 667);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 668);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 665);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 669);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 670);

  dawg_bool_t bSubstituted = dawg_arr_void_ptr_substitute(hArr1, (void*) 665, (void*) 700);
  CPPUNIT_ASSERT_EQUAL( (unsigned int) dawg_true, (unsigned int) bSubstituted );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 7, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 700, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 668, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 3) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 700, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 4) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 669, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 5) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 670, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 6) );

  dawg_arr_void_ptr_destroy(hArr1);
}


int compar(const void* el1, const void* el2)
{
    unsigned int nEl1 = (unsigned int) *(const void**) el1;
    unsigned int nEl2 = (unsigned int) *(const void**) el2;
    return nEl1 - nEl2;
}


void TestCase_DawgArr::test_sort_empty()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();

  dawg_arr_void_ptr_sort(hArr1, compar);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 0, dawg_arr_void_ptr_size(hArr1));

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_sort_one()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);

  dawg_arr_void_ptr_sort(hArr1, compar);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 1, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_sort_two()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 665);

  dawg_arr_void_ptr_sort(hArr1, compar);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 2, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 665, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );

  dawg_arr_void_ptr_sort(hArr1, compar);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 2, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 665, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );

  dawg_arr_void_ptr_destroy(hArr1);
}


void TestCase_DawgArr::test_sort_many()
{
  h_dawg_arr_void_ptr hArr1 = dawg_arr_void_ptr_create();
  dawg_arr_void_ptr_push_back(hArr1, (void*) 666);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 665);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 667);
  dawg_arr_void_ptr_push_back(hArr1, (void*) 664);

  dawg_arr_void_ptr_sort(hArr1, compar);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 4, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 664, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 665, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 3) );

  dawg_arr_void_ptr_sort(hArr1, compar);

  CPPUNIT_ASSERT_EQUAL( (unsigned int) 4, dawg_arr_void_ptr_size(hArr1));
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 664, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 0) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 665, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 1) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 666, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 2) );
  CPPUNIT_ASSERT_EQUAL( (unsigned int) 667, (unsigned int) dawg_arr_void_ptr_get_el(hArr1, 3) );

  dawg_arr_void_ptr_destroy(hArr1);
}


